class Solution(object):
    def longestBeautifulSubstring(self, word):
        d = {'a': 0, 'e': 1, 'i': 2, 'o': 3, 'u': 4}
        left = 0
        right = 0
        n = len(word)
        max_len = 0
        while right < n:
            while left < n and word[left] != 'a':
                left += 1
            if right <= left:
                right = left + 1
            else:
                if word[right] == word[right - 1] or d[word[right]] - d[word[right - 1]] == 1:
                    right += 1
                else:
                    if word[right - 1] == 'u':
                        max_len = max(max_len, right - left)
                    left = right
        if right <= n and word[right - 1] == 'u':
            max_len = max(max_len, right - left)
        return max_len


